<?php

require_once 'phpmoko/ui/HTML.php';
require_once 'phpmoko/ui/Widget.php';

class FormPanel extends Widget
{
	private $widget = null;
	private $script = null;
	
	/**
	 * Enter description here ...
	 * @var string
	 */
	private $title = null;

	function __construct()
	{
		parent::__construct();
	}

	function setScript($script)
	{
		$this->script = $script;
	}

	function setWidget($widget)
	{
		if ($widget instanceof Widget)
			$this->widget = $widget;
		else
			$this->widget = new HTML($widget);
	}

	/**
	 * @return the $title
	 */
	public function getTitle()
	{
		return $this->title;
	}

	/**
	 * @param string $title
	 */
	public function setTitle($title)
	{
		$this->title = $title;
	}

	function toString()
	{
		$str = '<form ';
		
		if ($this->id != null)
			$str .= ' id="'.$this->id.'"';
		
		$str .= ' action="'.$this->script.'" enctype="multipart/form-data" method="post">';
		
		if ($this->title != null)
		{
			$str .= '<fieldset>';
			$str .= '<legend>'.$this->title.'</legend>';
		}
		
		$str .= $this->widget->toString();
		
		if ($this->title != null)
			$str .= '</fieldset>';
		
		$str .= '</form>';
		
		return $str;
	}
}
?>